import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        list: [],
        detail: [],

    },
    mutations: {
        setState(state, ploader) {
            state[ploader.key] = ploader.value
        }
    },
    actions: {
        //渲染
        async getList({ commit }) {
            let res = await axios.get('/api/lists')
            console.log(res);
            commit('setState', { key: 'list', value: res.data.data })

        },
        //详情页
        async getDetail({ commit }, ploader) {
            let res = await axios.get('/api/detail/lists', { params: { id: ploader.id } })
            console.log(res);
            commit('setState', { key: 'detail', value: res.data.data })

        },
        //搜索
        async getLogin({ commit }, ploader) {
            let res = await axios.get('/api/search/lists', { params: { tt: ploader.tt } })
            console.log(ploader.tt);

            console.log(res);
            commit('setState', { key: 'list', value: res.data.data })

        },
        //登录
        // async LOGIN(context, ploader) {
        //     let res = await axios.post('/api/login/lists', ploader)
        //     console.log(res);

        // }
    },
    modules: {}
})